{include /common/header}
<script>
    var M={};
    $(function() {
        M.del = function(id){
            if (confirm('确定删除吗？')) {
                $.ajax({
                    url: '{:\mylib\Route::buildUrl('/admin/channel/del')}',
                    type: 'POST',
                    dataType: 'json',
                    data: {
                        id:id
                    },
                    success:function(res){
                        if (res.code) {
                            location.reload();
                        }else{
                            alert(res.message);
                        }
                    }
                });
            }
        }
    });
</script>
<p>
    <div class="btn-group">
      <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
        新增栏目 <span class="caret"></span>
      </button>
      <ul class="dropdown-menu">
        <li><a href="{:\mylib\Route::buildUrl('/admin/channel/add')}?pid=0&type=channel">封面</a></li>
        <li><a href="{:\mylib\Route::buildUrl('/admin/channel/add')}?pid=0&type=list">列表</a></li>
        <li><a href="{:\mylib\Route::buildUrl('/admin/channel/add')}?pid=0&type=page">单页</a></li>
        <li><a href="{:\mylib\Route::buildUrl('/admin/channel/add')}?pid=0&type=jump">跳转</a></li>
      </ul>
    </div>
</p>
{php}function _show($channels){{/php}
    {foreach $channels as $v}
    <tr>
        <td>{$v.id}</td>
        <td>{:str_repeat('&nbsp;&nbsp;&nbsp;&nbsp;', $v['_level'])}├&nbsp;{$v.title}</td>
        <td>{$v.path}</td>
        <td>{$v.type}</td>
        <td>{$v.nav}</td>
        <td>{$v.status}</td>
        <td>{$v.click}</td>
        <td>
            <a href="{:\mylib\Route::buildUrl('/admin/channel/edit')}?id={$v.id}">编辑</a>
            {if $v['subs']}
            <a href="#" onclick="alert('请先删除子栏目！');" style="color: #ddd;cursor: not-allowed;">删除</a>
            {else}
            <a href="#" onclick="M.del('{$v.id}')">删除</a>
            {/if}
            {if $v['type'] == 'list'}
                <a href="{:\mylib\Route::buildUrl('/admin/content/index')}?channel_id={$v.id}">内容管理</a>
            {/if}
        </td>
    </tr>
    {:_show($v['subs'])}
    {/foreach}
{php}}{/php}
<div class="table-responsive">
    <table class="table table-bordered table-striped">
        <thead>
            <tr>
                <th>#</th>
                <th>名称</th>
                <th>目录</th>
                <th>类型</th>
                <th>导航显示</th>
                <th>启用状态</th>
                <th>点击量</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>
            {:_show($channels)}
        </tbody>
    </table>
</div>
{include /common/footer}